package com.mdyy.server.tcp.controller;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.HexUtil;
import com.mdyy.server.tcp.component.NettyTcpServer;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/apple/")
public class AppleController {


    @GetMapping("test")
    public String test(String ip,String zhiling) {
        if (ip == null) {
            return "IP 不存在";
        }
        Channel channel = NettyTcpServer.map.get(ip);
        if(channel==null){
            return "channel 不存在";
        }

        channel.write(Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump(HexUtil.encodeHexStr(zhiling, CharsetUtil.CHARSET_UTF_8))));
        return "ok";
    }

}
